import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/size_util.dart';
import 'package:framelib/utils/string_util.dart';

/**
 * 加载dialog
 */
class LoadingDialog extends Dialog {

  LoadingDialog(this.canceledOnTouchOutside,{this.loadingText}) : super();

  ///点击背景是否能够退出
  final bool canceledOnTouchOutside;

  String? loadingText;

  @override
  Widget build(BuildContext context) {
    return SafeArea(child: Center(
      child: Material(
        ///背景透明
          color: color_transparent,
          ///保证控件居中效果
          child: Stack(
            children: <Widget>[
              GestureDetector(
                ///点击事件
                onTap: (){
                  if(canceledOnTouchOutside){
                    Navigator.pop(context);
                  }
                },
              ),
              _dialog()
            ],
          )
      ),
    ));
  }

  Widget _dialog(){
    return Center(
      ///弹框大小
      child: SizedBox(
        width: size_120.w,
        height: size_120.w,
        child: Container(
          ///弹框背景和圆角
          decoration: ShapeDecoration(
            color: color_ffffff,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(
                Radius.circular(size_8.w),
              ),
            ),
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              SizedBox(
                width: size_36.w,
                height: size_36.w,
                child: CircularProgressIndicator(),
              ),
              Padding(
                padding:  EdgeInsets.only(
                  top: size_20.h,
                ),
                child: new Text(
                  loadingText??"${loading}...",
                  style: TextStyle(fontSize: size_16.h),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}